﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>短信管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="/JqueryPlug/dtGrid/jquery.dtGrid.css" rel="stylesheet">
    <link href="/CSS/Base/BaseClass.css?cssver=4" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-1.11.2.min.js"></script>
    <script src="/JqueryPlug/layer/layer/layer.js"></script>
    <script src="/Scripts/avalon.min.js"></script>
    <script src="/JqueryPlug/dtGrid/jquery.dtGrid.js"></script>
    <script src="/Scripts/SZHLCommon.js?jsver=5"></script>
    <script>

        var grid, dtoption, viewindex;

        //获取主要菜单
        dtoption = {
            lang: 'zh-cn',
            check: false,
            ajaxLoad: false,
            exportFileName: '短信类表',
            columns: [
                { id: 'ID', title: '序号', type: 'string', columnClass: 'text-center', hide: true },
                { id: 'dxContent', title: '短信内容', type: 'string', columnClass: 'text-center', columnStyle: "width:400px" },
                { id: 'dxnums', title: '接收号码', type: 'string', columnClass: 'text-center' },
                { id: 'SendTime', title: '发送日期', type: 'string', columnClass: 'text-center' },
                { id: 'CRDate', title: '添加日期', type: 'string', columnClass: 'text-center' },
                {
                    id: 'CRUser', title: '发送人', type: 'string', columnClass: 'text-center', resolution: function (value, record, column, grid, dataNo, columnNo) {
                        return ComFunJS.convertuser(record.CRUser, 100);
                    }
                },
                    {
                        id: 'Option', title: '操作', type: 'string', columnClass: 'text-center', resolution: function (value, record, column, grid, dataNo, columnNo) {
                            var content = '<button class="btn btn-xs btn-danger"  style="margin-left:10px;"  onclick="DelDX(\'' + record.ID + '\',' + dataNo + ')"><i class="fa fa-trash-o"></i>  删除</button>';
                            return content;
                        }
                    }
            ],
            gridContainer: 'dtgrid',
            toolbarContainer: 'dtgridTool',
            pageSize: 10,
            pageSizeLimit: [10, 20, 50],
            tools: 'faseQuery',
            onGridComplete: function (grid) {
                var log = '<p>表格加载完成。表格编号：' + grid.option.id + '。</p>';
            }
        };
        var model = avalon.define({
            $id: "APP_DXGL",
            modelData: { "dxContent": "", "dxnums": "", "SendTime": "" },
            menuType: 0,
            MsgCount: "",
            selmenu: function (menuType) {
                model.menuType = menuType;
            },
            SaveData: function (dom) {
                var errmsg = "";
                if ($(".szhl_require")) {
                    $(".szhl_require").each(function () {
                        if ($(this).val() == "") {
                            errmsg = $(this).prev("label").text() + "不能为空\r\n";
                            return false;
                        }
                    })
                }
                if (errmsg !== "") {
                    layer.tips(errmsg, dom);
                } else {
                    if ($("input[type=checkbox]").prop("checked") && model.modelData.SendTime == "") {
                        layer.tips("发送时间不能为空", dom);
                        return;
                    }
                    var modelValue = JSON.stringify(model.modelData.$model);
                    $.post('/API/FTAPI.ashx?Action=ADDDXGL', { "P1": modelValue }, function (result) {
                        var result = $.parseJSON(result);
                        if (result.ErrorMsg == "") {
                            parent.ComFunJS.winsuccess("发送成功");
                        } else {

                            parent.ComFunJS.winsuccess("发送失败");
                        }
                    })
                }
            },
            SearchContent: "",
            CommonData: [],
            GetDataList: function () {
                $.getJSON('/API/FTAPI.ashx?Action=GETDXGLLIST', { P1: model.SearchContent }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        model.CommonData = resultData.Result;
                        if (!model.MsgCount) {
                            model.MsgCount = model.CommonData.size() > 0 ? model.CommonData.size() : "";
                        }
                        if (dtoption.datas != undefined) {
                            dtoption.originalDatas = model.CommonData;

                        } else {
                            dtoption.datas = model.CommonData;
                            grid = $.fn.DtGrid.init(dtoption);
                        }
                        grid.load()
                    }
                })

            }, GetUserPhone: function () {
                parent.ComFunJS.winbtnwin("/View/Base/UserSelect.html", "选择用户手机", 900, 540, {}, function (layero, index) {
                    var frameid = $("iframe", $(layero)).attr('id');
                    var people = parent.window.frames[frameid].getqiandaopeople();
                    $("#dxphone").val(people.phone);
                    parent.layer.close(index)
                })
            }, GetKHPhone: function () {
                parent.ComFunJS.winbtnwin("/View/APPBaseView/KHGLSelect.html", "选择客户手机", 900, 540, {}, function (layero, index) {
                    var frameid = $("iframe", $(layero)).attr('id');
                    var phone = parent.window.frames[frameid].model.GetCheckPhone();
                    $("#dxphone").val(phone);
                    parent.layer.close(index)
                })
            }
        });
        function DelDX(Id, rowNumber) {
            if (confirm("确定要删除么？")) {
                $.post("/API/FTAPI.ashx", { Action: "DELDXGL", P1: Id }, function (result) {
                    var jsonresult = $.parseJSON(result)
                    if ($.trim(jsonresult.ErrorMsg) != "") {
                        parent.ComFunJS.winwarning(jsonresult.ErrorMsg);
                    } else {
                        model.CommonData.remove(model.CommonData[rowNumber]);
                        dtoption.originalDatas = model.CommonData;
                        grid.load()
                        parent.ComFunJS.winsuccess("删除成功");
                    }
                })
            }
        }
        $(function () {
            model.GetDataList();
            ComFunJS.initForm();
            $("input[type=checkbox]").click(function () {
                $(".szhl_form_date_time").toggle();
                if (!$("input[type=checkbox]").prop("checked")) {
                    model.modelData.SendTime = "";
                    $("button[type=button]").text("立即发送")
                } else {
                    $("button[type=button]").text("定时发送")
                }
            })
        })
    </script>
</head>
<body ms-controller="APP_DXGL">
    <div class="container-fluid maindiv" style="margin-top: 20px" id="dvContent">
        <div style="width:120px;position:absolute">
            <ul class="list-group text-center  leftmenu ">
                <li class="list-group-item sel" ms-class-1="sel:model.menuType==0" ms-click="selmenu(0)">
                    <div>
                        <i class="iconfont icon-duanxin hvr-grow"></i>
                    </div>
                    <div>发送短信</div>
                </li>
                <li class="list-group-item " ms-class-1="sel:model.menuType==1" style="border-top:0;margin-top:2px" ms-click="selmenu(1)">
                    <div>
                        <i class="iconfont icon-47gekeshiduanxintongji hvr-grow "></i>{{MsgCount}}
                    </div>
                    <div>已发短信</div>
                </li>
            </ul>
        </div>

        <div class="row contentdv" style="margin-left:121px">
            <div class="col-xs-12 " ms-if="model.menuType==1">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-xs-10">
                                <div class="input-group">
                                    <div class="input-group-addon">查询条件</div>
                                    <input id="tbSearch" class="form-control" type="text" ms-duplex="SearchContent" placeholder="输入短信内容查询" />
                                    <span class="input-group-btn">
                                        <button class="btn btn-info" ms-click="GetDataList()">查询</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="dtgrid" style="margin-top:20px"></div>
                <div id="dtgridTool" class="dt-grid-toolbar-container"></div>
            </div>
            <div class="col-xs-12 " ms-if="model.menuType==0">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="form-group">
                            <label>短信接收号码</label>
                            <textarea class="form-control szhl_require" ms-duplex="modelData.dxnums" id="dxphone"></textarea>
                            <a href="javascript:void(0)" ms-click="GetUserPhone()">+从员工中选取号码</a>
                            <a href="javascript:void(0)" ms-click="GetKHPhone()" style="margin-left: 20px">+从客户列表中选取号码</a>
                        </div>
                        <div class="form-group">
                            <label>短信内容（不超过80字）</label>
                            <textarea class="form-control szhl_require" maxlength="80" ms-duplex="modelData.dxContent"></textarea>
                        </div>
                        <div class="checkbox">
                            <label>
                                <input type="checkbox">
                                定时发送
                            </label>
                            <input type="text" value="" ms-duplex="modelData.SendTime" class="szhl_form_date_time form-control" style="display:none;" placeholder="请输入发送时间" />
                        </div>
                        <button type="button" class="btn btn-default" ms-click="SaveData(this)">立即发送</button>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <script src="/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
</body>
</html>
